<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\admin\model\goods\Order;
use app\common\controller\Api;
use app\common\controller\Payment;
use think\Controller;
use think\Db;
use think\Request;


class Dynamicsegregates extends Api
{
    private static $model;
//    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';


    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        self::$model = new \app\common\model\DynamicSegregates();
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function create()
    {
        $dynamicId = input('dynamic_id');
        if (!$dynamicId) {
            $this->error('参数缺失！');
        }

        $dynamicInfo = \app\common\model\UserDynamics::find($dynamicId);
        if (!$dynamicInfo) {
            $this->error('该动态不存在！');
        }

        $userId = $this->auth->id;
        if ($dynamicInfo->user_id == $userId) {
            $this->error('不可屏蔽自己的动态！');
        }

        $where = [
            'user_id' => $userId,
            'dynamic_id' => $dynamicId,
        ];

        $row_info = self::$model->where($where)->find();
        if (!$row_info) {
            $pdata = [
                'user_id' => $this->auth->id,
                'dynamic_id' => $dynamicId,
            ];

            $res = self::$model->create($pdata);
            if (!$res) {
                $this->error('屏蔽失败！');
            }
            $this->success('屏蔽成功！');
        } else {
            $res = self::$model->where('id', $row_info->id)->delete();
            if (!$res) {
                $this->error('取消屏蔽失败！');
            }
            $this->success('取消屏蔽成功！');
        }
    }
}
